package com.example.firstopengl.data;

import android.opengl.GLES20;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import static com.example.firstopengl.util.Constant.BYTES_PER_FLOAT;

/**
 * Created by liqian-ps on 2017/7/6.
 */

public class VertexArray {
    private final FloatBuffer floatBuffer;
//    private static final int BYTES_PER_FLOAT = 4;



    public VertexArray(float[] vertexData){
        floatBuffer = ByteBuffer.allocateDirect(vertexData.length * BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).
                asFloatBuffer().put(vertexData);

    }

    public void setVertexAttribPointer(int dataOffset, int attributeLocation, int componentCount, int stride){
        floatBuffer.position(dataOffset);
        GLES20.glVertexAttribPointer(attributeLocation, componentCount, GLES20.GL_FLOAT, false, stride,  floatBuffer);
        GLES20.glEnableVertexAttribArray(attributeLocation);
        floatBuffer.position(0);
    }
}
